<?php
/**
 * 管理员导出日志
 */
namespace App\Models\MainDB;

use App\Enums\ExportEnum;
use Illuminate\Database\Eloquent\Model;

class AdminExportLog extends Model
{

    protected $table = 'ln_admin_export_log';

    protected $primaryKey = 'id';

    protected $fillable = [
        'id', //主键ID
        'admin_id', //管理员id
        'title', //标题
        'data_no', //导出数据编号，见app/enum/ExportEnum
        'status', //状态：0：未完成；1：导出成功；2：导出失败
        'condition', //筛选条件
        'download_url', //下载链接
    ];

    public $timestamps = false;

    public function add($dataNo, $params, $downloadUrl)
    {
        return $this->insert([
            'title' => ExportEnum::NO[$dataNo]['desc_ch'],
            'admin_id' => app('request')->admin_id,
            'data_no' => $dataNo,
            'condition' => json_encode($params),
            'status' => ExportEnum::NO[$dataNo]['is_sync'] == 1 ? 1 : 0,
            'download_url' => $downloadUrl,
        ]);
    }

}